<template>
  <div>
    <NavBar :title="title" />
    <div class="content-top">
      <MyEmpty v-if="loading === false && list.length === 0" />
      <van-list class="my-shield-list" v-model="loading" :finished="!loading" @load="onLoad" v-else>
        <van-swipe-cell class="shield-item" v-for="(item, index) in list" :key="index">
          <div class="name" @click="onCompanyClick(item.CompanyID)">
            <span>{{ item.CompanyName }}</span>
          </div>
          <template #right>
            <van-button square text="删除" type="danger" style="height: 100%" @click="onDel(index, item.itemID)" />
          </template>
        </van-swipe-cell>
      </van-list>

    </div>
    <!-- 添加按钮 start -->
    <div class="my-shield-add">
      <van-button block round type="primary" color="#05A6F0" text="添加屏蔽企业" style="font-size: 18px" @click="onAdd">
      </van-button>
    </div>
    <!-- 添加按钮 end -->
  </div>
</template>

<script>
import NavBar from "@/components/NavBar.vue";
import MyEmpty from "@/components/MyEmpty.vue";
import { List, Button, SwipeCell, Toast, Dialog, Cell } from "vant";
import { mixin_person_toJobCompany } from "@/mixin/mixins";
export default {
  name: "RefuseCompany",
  components: { NavBar, MyEmpty, [List.name]: List, [Button.name]: Button, [SwipeCell.name]: SwipeCell, [Cell.name]: Cell },
  props: ["title"],
  mixins: [mixin_person_toJobCompany],
  // 定义属性
  data() {
    return {
      loading: true,
      list: [],
    };
  },
  mounted() { },
  activated() {
    this.onLoad();
  },
  // 方法集合
  methods: {
    onLoad() {
      this.loading = true;
      this.$api.get('/Resume/GetCompanyPageListRefusedByPerson').then(res => {
        this.loading = false;
        if (res.success) {
          this.loading = false;
          this.list = res.response;
        }
      })
    },
    onDel(index, companyid) {
      Dialog.confirm({ message: "确认删除该企业？"}).then(() => {
        this.$api.post('/PAC/DelRefuseCompany?companyId='+companyid).then(res => {
          if (res.success) {
            Toast.success('删除成功');
            this.list.splice(index, 1);
          }
          else { Toast.fail(res.msg) }
        })
      })
    },
    onAdd() {
      this.$router.push({ name: "person-refuse-add" });
    },
  },
};
</script>

<style lang="less">
@import "vant/lib/dialog/index.less";
@import "@/assets/css/common.less";

.my-shield-list {
  padding-bottom: 62.5px;
}

.my-shield-list .shield-item {
  background-color: #fff;
}

.my-shield-list .shield-item + .shield-item {
  border-top: 0.5px solid #e8e8e8;
}

.my-shield-list .name {
  padding: 14px 15px;
  font-size: 16px;
  color: #333;
}

.my-shield-add {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 333;
  display: flex;
  align-items: center;
  height: 42px;
  padding: 10px 20px;
  border-top: 0.5px solid #e8e8e8;
  background-color: #fff;
}
</style>